package top.glike.ssl.auto.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.glike.ssl.auto.domain.SslDomainCertificate;
import top.glike.ssl.auto.mapper.SslDomainCertificateMapper;
import top.glike.ssl.auto.service.ISslDomainCertificateService;

import java.util.Date;
import java.util.List;

/**
 * 域名管理Service业务层处理
 *
 * @author Sophia
 * @date 2025-10-12
 */
@Service
public class SslDomainCertificateServiceImpl implements ISslDomainCertificateService {
    @Autowired
    private SslDomainCertificateMapper sslDomainCertificateMapper;

    /**
     * 查询域名管理
     *
     * @param id 域名管理主键
     * @return 域名管理
     */
    @Override
    public SslDomainCertificate selectSslDomainCertificateById(Long id) {
        return sslDomainCertificateMapper.selectSslDomainCertificateById(id);
    }

    /**
     * 查询域名管理列表
     *
     * @param sslDomainCertificate 域名管理
     * @return 域名管理
     */
    @Override
    public List<SslDomainCertificate> selectSslDomainCertificateList(SslDomainCertificate sslDomainCertificate) {
        return sslDomainCertificateMapper.selectSslDomainCertificateList(sslDomainCertificate);
    }

    /**
     * 新增域名管理
     *
     * @param sslDomainCertificate 域名管理
     * @return 结果
     */
    @Override
    public int insertSslDomainCertificate(SslDomainCertificate sslDomainCertificate) {
        sslDomainCertificate.setUpdatedTime(new Date());
        sslDomainCertificate.setCreatedTime(sslDomainCertificate.getUpdatedTime());
        return sslDomainCertificateMapper.insertSslDomainCertificate(sslDomainCertificate);
    }

    /**
     * 修改域名管理
     *
     * @param sslDomainCertificate 域名管理
     * @return 结果
     */
    @Override
    public int updateSslDomainCertificate(SslDomainCertificate sslDomainCertificate) {
        sslDomainCertificate.setUpdatedTime(new Date());
        return sslDomainCertificateMapper.updateSslDomainCertificate(sslDomainCertificate);
    }

    /**
     * 批量删除域名管理
     *
     * @param ids 需要删除的域名管理主键
     * @return 结果
     */
    @Override
    public int deleteSslDomainCertificateByIds(Long[] ids) {
        return sslDomainCertificateMapper.deleteSslDomainCertificateByIds(ids);
    }

    /**
     * 删除域名管理信息
     *
     * @param id 域名管理主键
     * @return 结果
     */
    @Override
    public int deleteSslDomainCertificateById(Long id) {
        return sslDomainCertificateMapper.deleteSslDomainCertificateById(id);
    }

    @Override
    public SslDomainCertificate getDomainByDomainName(String domainName) {
        return sslDomainCertificateMapper.getDomainByDomainName(domainName);
    }

    @Override
    public SslDomainCertificate saveSslDomainCertificate(SslDomainCertificate sslDomainCertificate) {
        if (sslDomainCertificate.getId() != null) {
            sslDomainCertificate.setUpdatedTime(new Date());
            sslDomainCertificateMapper.updateSslDomainCertificate(sslDomainCertificate);
        } else {
            sslDomainCertificate.setUpdatedTime(new Date());
            sslDomainCertificate.setCreatedTime(sslDomainCertificate.getUpdatedTime());
            sslDomainCertificateMapper.insertSslDomainCertificate(sslDomainCertificate);
        }
        return sslDomainCertificate;
    }

}
